﻿@model WeddingEventManagement_API.Location
@{
    ViewBag.Title = Model.Name;
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<Event> events = ViewBag.Events;
}

<div id="location-details" class="twelve columns">
    <div class="row">
        <div class="twelve columns">
            <div id="map_canvas" style="width:100%; height:250px;" data-address="@Model.StreetAddress, @Model.City, @Model.Province, @Model.PostalCode"></div>
            <div class="location-photo">
                @if (Model.LocationPhotos.Count() < 1)
                {
                    <i class="icon-pictures"></i>
                }
                else
                {
                    <img src="~/Content/Uploads/@Model.LocationPhotos.FirstOrDefault().Filename" />
                }
                <a data-reveal-id="add-photos" href class="button">Add Photos</a>
            </div>
            <div class="location-info">
                <div class="info">
                    <h4>@Model.Name</h4>
                    <h5>@Model.StreetAddress <br/> @Model.City, @Model.Province @Model.PostalCode</h5>
                </div>
            </div>
        </div>
        
    </div>
    <br/>
    <div class="row">
        <div class="four column mobile-four">
            <div class="card card-blue">
                <h5>Upcoming Events</h5>
                @if (events.Where(i => i.StartDate.ToLocalTime() >= DateTime.Now).Count() > 0)
                {
                    <ul class="event-list no-bullet">
                    @foreach (var item in events.Where(i => i.StartDate.ToLocalTime() > DateTime.Now).OrderByDescending(i => i.StartDate))
                    {
                        <li>
                            <a href="@Url.Action("Details", "Event", new { id = item.EventID })" class="clearfix" style="border-color: @item.EventType.CalendarColor">
                                <span class="event-date" style="background: @item.EventType.CalendarColor">
                                    <span class="event-dd">@item.StartDate.Day</span>
                                    <span class="event-mm">@item.StartDate.ToString("MMM")</span>
                                </span>
                                <span class="event-title">
                                    <p>@item.Title</p>
                                    <span><i class="icon-clock"></i> @item.StartDate.ToShortTimeString()</span>
                                </span>
                            </a>
                        </li>
                    }
                    </ul>
                }
                else
                {
                    <p>No upcoming events for this location...</p>
                }
            </div>
            <div class="card card-blue">
                <h5>Past Events</h5>
                @if (events.Where(i => i.StartDate.ToLocalTime() < DateTime.Now).Count() > 0)
                {
                    <ul class="event-list no-bullet">
                    @foreach (var item in events.Where(i => i.StartDate.ToLocalTime() < DateTime.Now).OrderByDescending( i => i.StartDate))
                    {
                        <li>
                        <a href="@Url.Action("Details", "Event", new { id = item.EventID })" class="clearfix" style="border-color: @item.EventType.CalendarColor">
                            <span class="event-date" style="background: @item.EventType.CalendarColor">
                                <span class="event-dd">@item.StartDate.Day</span>
                                <span class="event-mm">@item.StartDate.ToString("MMM")</span>
                            </span>
                            <span class="event-title">
                                <p>@item.Title</p>
                                <span><i class="icon-clock"></i> @item.StartDate.ToShortTimeString()</span>
                            </span>
                        </a>
                        </li>
                    }
                    </ul>
                }
                else
                {
                    <p>No past events for this location...</p>
                }
            </div>
        </div>

        <div class="four column mobile-four">
            <div class="card card-blue">
                <h5>Photos</h5>

                @if (Model.LocationPhotos.Count() > 0)
                {
                    foreach (var item in Model.LocationPhotos)
                    {
                        <img src="~/Content/Uploads/@item.Filename" />
                    }
                }
                else
                {
                    <div class="text-center" style="background: #eee;padding: 20px; color: #999; ">
                        <i class="icon-pictures" style="font-size: 100px"></i>
                    </div>
                }
                
            </div>
        </div>

        <div class="four column mobile-four">
            <div class="card card-blue">

                <h5>Details</h5>
                <span style="position: absolute; top: 5px; right: 5px;">
                        @Html.ActionLink("Edit", "Edit", new { id = Model.LocationID }, new { @class = "button secondary radius" })
                </span>

                <div class="row">
                    <div class="microstat mobile-four">
                        <h5>@events.Count()</h5>
                        <p>Events</p>
                    </div>
                    <div class="microstat mobile-four">
                        <h5>@ViewBag.AverageCost</h5>
                        <p>Avg Cost</p>
                    </div>
                    <div class="microstat mobile-four">
                        <h5>@(Model.Capacity.HasValue ? Model.Capacity.Value.ToString() : "N/A")</h5>
                        <p>Capacity</p>
                    </div>
                </div>

                <br>

                <div class="row">
                    <div class="two column mobile-one">
                        <i class="icon-arrow-up-5"></i>
                    </div>
                    <div class="ten column mobile-three">
                        <a target="_blank" href="http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=@ViewBag.CompanyAddress @ViewBag.CompanyCity @ViewBag.CompanyProvince @ViewBag.CompanyPostal&daddr=@Model.StreetAddress, @Model.City @Model.Province @Model.PostalCode">Directions</a>
                    </div>
                </div>

                @if (!String.IsNullOrEmpty(Model.ContactPhone))
                {
                    <br>
                    <div class="row">
                        <div class="two column mobile-one">
                            <label for="@Html.IdFor(m => m.ContactPhone)"><i class="icon-phone"></i></label>
                        </div>
                        <div class="ten column mobile-three">
                            <a href="tel:@Model.ContactPhone">@Html.DisplayFor(m => m.ContactPhone)</a>
                        </div>
                    </div>
                }

                @if (!String.IsNullOrEmpty(Model.ContactEmail))
                {
                    <br>
                    <div class="row">
                        <div class="two column mobile-one">
                            <label for="@Html.IdFor(m => m.ContactEmail)"><i class="icon-mail"></i></label>
                        </div>
                        <div class="ten column mobile-three">
                            <a href="mailto:@Model.ContactEmail" target="_blank">@Html.DisplayFor(m => m.ContactEmail)</a>
                        </div>
                    </div>
                }

                @if (!String.IsNullOrEmpty(Model.Website))
                {
                    <br>
                    <div class="row">
                        <div class="two column mobile-one">
                            <label for="@Html.IdFor(m => m.Website)"><i class="icon-globe"></i></label>
                        </div>
                        <div class="ten column mobile-three">
                            <a href="@Model.Website" target="_blank">Website</a>
                        </div>
                    </div>
                }

                @if (!String.IsNullOrEmpty(Model.ContactName))
                {
                    <br>
                    <div class="row">
                        <div class="two column mobile-one">
                            <label for="@Html.IdFor(m => m.ContactName)"><i class="icon-user"></i></label>
                        </div>
                        <div class="ten column mobile-three">
                            @Html.DisplayFor(m => m.ContactName)
                        </div>
                    </div>
                }


                @if (!String.IsNullOrEmpty(Model.Notes))
                {
                    <br>
                    <div class="row">
                        <div class="two column mobile-one">
                            <label for="@Html.IdFor(m => m.Notes)"><i class="icon-pencil"></i></label>
                        </div>
                        <div class="ten column mobile-three">
                            @Html.Raw(Model.Notes)
                        </div>
                    </div>
                }

                </div>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <div id="add-photos" class="reveal-modal">
        @using (Html.BeginForm("PhotoUpload", "Location", new { id = Model.LocationID }, FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <h5><i class="icon-pictures"></i> Upload Location Photos</h5>
            <div class="row">
                <label for="file1">Filename:</label>
                <input type="file" name="files[0]" id="file1" />
  
                <label for="file2">Filename:</label>
                <input type="file" name="files[1]" id="file2" />

                <input type="submit" class="button" value="Upload" />
            </div>
        }
        <a class="close-reveal-modal">&#215;</a>
    </div>
    <script src="~/Scripts/locationDetails.js"></script>
    <script>
        $('#form-container > form').submit(function (e) {
            var r = confirm("Are you sure you want to delete @Model.Name");
            if (r === false) {
                e.preventDefault();
            }
        });
    </script>
}